#include "EventPoller.h"
#include "EventHandler.h"
#include <SDL.h>
//#include <assert.h>


void EventPoller::Update()
{
    SDL_Event event;
    Handlers handlers = m_handlers;

    while (SDL_PollEvent(&event))
    {
        if (event.type == SDL_QUIT)
        {
            exit(0);
        }

        for (Handlers::iterator it = handlers.begin(); 
             it != handlers.end();
             ++it)
        {
            (*it)->HandleEvent(event);
        }
    }
}

void EventPoller::AddHandler(EventHandler* eh)
{
    m_handlers.insert(eh);
}

void EventPoller::RemoveHandler(EventHandler* eh)
{
    //assert(m_handlers.find(eh) != m_handlers.end());

    m_handlers.erase(eh);
}
